package org.lionel.simpleioc;

public class Factory {
//    public static Fruit getInstance(String className){
//        Fruit f = null;
//
//        try {
//            f = (Fruit)Class.forName(className).newInstance();
//        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
//            e.printStackTrace();
//        }
//        return f;
//    }
    public static Fruit getInstance(Class<Apple> clazz){
        Fruit f = null;
        try {
            f = clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return f;
    }

    public static void main(String[] args) {
//        Fruit f = Factory.getInstance("org.lionel.simpleioc.Apple");
//        if (f!=null){
//            f.eat();
//        }
        Fruit fruit = getInstance(Apple.class);
        fruit.eat();
    }
}
